<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>管理后台</title>
    <!--大拇指-->
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/res/css/login.css">
</head>
<body>
<div class="container">
    <form class="layui-form" action="">
        <div class="login-top">
            <div class="title-bar">
                <img src="/static/res/img/icon_blue.png" />
                <label>管理后台</label>
            </div>
            <input class="layui-input" type="text" name="account" lay-verify="account" placeholder="请输入账号" >
            <input class="layui-input" type="password" name="password" lay-verify="pass" autocomplete="off" placeholder="请输入密码" >
            <!--<div class="btn">-->
                <!--<a class="forget-password" href="javascript:void(0)">forgot password</a>-->
                <!--<button class="layui-btn login" lay-submit="" lay-filter="confirm">login</button>-->
            <!--</div>-->
        </div>
        <div class="login-bottom" lay-submit="" lay-filter="confirm">
            <!--<h3>New User &nbsp;<a href="index">Register</a>&nbsp; Here</h3>-->
            <h3>登录</h3>
        </div>
    </form>
</div>

<script src="/static/layui/layui.js" charset="utf-8"></script>
<script src="/static/res/js/web-util.js" charset="utf-8"></script>

<script>
    layui.use('form', function(){
        var form = layui.form;
        var layer = layui.layer;

        //自定义验证规则
        form.verify({
            account: function(value){
                if(value.length <= 0){
                    return '您还没有填写账号';
                }
            },
            pass: function(value){
                if(value.length <= 0){
                    return '您还没有填写密码';
                }
            }
        });

        //监听提交
        form.on('submit(confirm)', function(data){
//            var $ = layui.jquery;
            var account = data.field.account;
            var password = data.field.password;

            var keyArray = ['userName', 'passWord'];
            var valueArray = [account, password];
            getData(apiUrl.api_login, true, keyArray, valueArray, function (msg) {
//                console.log(msg);
                if (msg["code"] == 0) {
                    layui.data('userInfo', {
                        key: 'data',
                        value: msg["data"]
                    });
                    layer.msg("登录成功");
                    setTimeout(function(){
                        window.location.href='./index';
                    },1000);
                } else {
                    layer.msg(msg["msg"]);
                }
            });

//            setInterval(function(){
//                layer.close(index)
//                if (account == 'test' && password == '555555') {
//                    layer.msg('登录成功');
//                    setInterval(function(){
//                        window.location.href='./Index.html';
//                    },1000);
//                } else {
//                    layer.msg('账号或者密码错误');
//                }
//            },2000);

//            $.ajax({
//                type: "get",//请求方式
//                dataType: "text",//数据类型
//                url: "https://www.sojson.com/open/api/weather/json.shtml?city=长沙市",//请求地址
//                success: function (msg) {
//                    layer.msg(msg)
//                },
//                error:function (textStatus) {//请求失败后调用的函数
//                    console.log(textStatus)
//                }
//            });


//            var xmlhttp;
//            if (window.XMLHttpRequest)
//            {// code for IE7+, Firefox, Chrome, Opera, Safari
//                xmlhttp=new XMLHttpRequest();
//            }
//            else
//            {// code for IE6, IE5
//                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
//            }
//            xmlhttp.onreadystatechange=function()
//            {
//                if (xmlhttp.readyState==4 && xmlhttp.status==200)
//                console.log(xmlhttp)
//            };
//            xmlhttp.open("GET","https://www.sojson.com/open/api/weather/json.shtml?city=长沙市",true);
//            xmlhttp.send();

            return false;
        });

    });
</script>
</body>
</html>